package com.tiger.cloud.service.crm;

import com.tiger.cloud.model.crm.AppSystemMessage;
import com.tiger.cloud.dao.crm.AppSystemMessageDao;
import com.tiger.cloud.enums.AppSystemMessageStatus;
import com.tiger.cloud.enums.AppSystemMessageType;
import com.tiger.cloud.enums.DeleteEnum;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.tiger.cloud.common.mybatis.TigerBaseService;
import com.tiger.cloud.common.mybatis.MybatisTigerDao;

/**
 * 系统消息
 */
@Service("appSystemMessageService")
public class AppSystemMessageService extends TigerBaseService<AppSystemMessage> implements IAppSystemMessageService{
    
    @Autowired
	private AppSystemMessageDao appSystemMessageDao;

	@Override
	public MybatisTigerDao<AppSystemMessage> getEntityDao() {
		return appSystemMessageDao;
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public AppSystemMessage addMessage(Long sendUserId,Long receiveUserId, String string, AppSystemMessageType friendsMsg) {
		AppSystemMessage appSystemMessage=new AppSystemMessage();
		appSystemMessage.setContent(string);
		appSystemMessage.setIsDelete(DeleteEnum.NOMAIL);
		appSystemMessage.setStatus(AppSystemMessageStatus.UN_READED);
		appSystemMessage.setType(AppSystemMessageType.FRIENDS_MSG);
		appSystemMessage.setReceiveUserId(receiveUserId);
		appSystemMessage.setSendUserId(sendUserId);
		if(appSystemMessageDao.insert(appSystemMessage)>0){
			return appSystemMessage;
		}
		return null;
	}
    
}